import { mathType } from "./face";

// 按钮意图配置接口
interface ButtonIntentConfig {
    text: string;
    action: Function;
    mathType?: mathType;
}

//文字样式基础结构
export class Icard {
    list:string[] = [];
    _button:string[] = [];
    private Bigtitle:boolean = false;
    constructor() {
    }
    l(text:string){
        this.list.push(text);
    }
    title(text:string){
        const emojiRegex = /\p{Emoji}/u; // 使用更通用的正则表达式来检查emoji
        if(!this.Bigtitle){
            if (emojiRegex.test(text)) {
                this.list.push(`┏┄━═${text}═━┄`);
            } else {
                this.list.push(`┏┄━═✉️${text}═━┄`);
            }
        }else{
            if (emojiRegex.test(text)) {
                this.list.push(`┄━═${text}═━┄`);
            } else {
                this.list.push(`┄━═✉️${text}═━┄`);
            }
            
        }
        this.Bigtitle = true;
    }
    button(text:string,cb?:()=>void){
        this._button.push(`[${text}]`);
        if(cb){
            cb();
        }
    }
    
    // 封装的按钮意图注册方法
    registerButtonIntents(
        buttonConfigs: ButtonIntentConfig[], 
        component: any, 
        target: any = null
    ): void {
        buttonConfigs.forEach(config => {
            this.button(config.text, () => {
                const mathTypeToUse = config.mathType || mathType.完全匹配;
                component.registerIntent(mathTypeToUse, config.text, config.action, false);
            });
        });
    }
    
    //两个Icard合并
    merge(card:Icard){
        this.list.push(...card.list);
    }
    getText(){
        let text = this.list.join('\n');
        if(this._button.length > 0){
            text += '\n┏┄━═💡指令提示═━┄\n';
            
            for(let i = 0; i < this._button.length; i++){
                text += this._button[i];
                if((i + 1) % 3 === 0 && i !== this._button.length - 1){
                    text += '\n';
                } else if(i !== this._button.length - 1){
                    text += ' ';
                }
            }
            // text += '\n┗┄━°❀•°💡°❀•°═━┄';
        }
        // text += '\n┗━━━━━━━━━━━━┄'
        return text;
    }
}

// 导出接口供其他文件使用
export { ButtonIntentConfig };
